const fileManager = wx.getFileSystemManager();
const getBase64ImagePath = (base64data, mode = '') => {
	base64data = base64data.replace(/[\r\n]/g, '');
	let arrayBuffer = uni.base64ToArrayBuffer(base64data);
	let filePath = `${wx.env.USER_DATA_PATH}/share_qrcode${mode}.jpg`;
	return new Promise(resolve => {
		fileManager.writeFile({
			filePath: filePath,
			data: arrayBuffer,
			encoding: 'base64',
			success: res => {
				resolve(filePath);
			},
			fail: res => {
				resolve(base64data);
			}
		});
	});
}

module.exports = {
	getBase64ImagePath: getBase64ImagePath
};
